package com.gpframework.module.controller.wages;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.core.page.TableDataInfo;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.common.utils.poi.ExcelUtil;
import com.gpframework.module.wages.domain.GzHolidays;
import com.gpframework.module.wages.domain.req.GzHolidaysAdd;
import com.gpframework.module.wages.domain.req.GzHolidaysReq;
import com.gpframework.module.wages.domain.req.GzHolidaysUpdate;
import com.gpframework.module.wages.domain.vo.GzHolidaysVo;
import com.gpframework.module.wages.service.IGzHolidaysService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
/**
 * @ClassName GzHolidaysController
 * @Author gpframework
 * @Date 2024-04-24
 * @Version 1.0.0
 * @Description 广州人事基本工资Controller
 */
@Validated
@Api(tags = "广州人事基本工资")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@SuppressWarnings({"rawtypes","unchecked"})
@RequestMapping("/wage/holidays" )
public class GzHolidaysController extends BaseController {

    private final IGzHolidaysService iGzHolidaysService;

 /**
  * @Description 分页
  * @Author gpframework
  * @Date 2024-04-24
  * @Param gzHolidays
  * @Return TableDataInfo
 */
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('wage:holidays:list')")
    @GetMapping("/list")
    public TableDataInfo<GzHolidaysVo> list(GzHolidaysReq gzHolidaysReq)
    {
        startPage();
        QueryWrapper<GzHolidays> lqw = new QueryWrapper<GzHolidays>();
        gzHolidaysReq.generatorQuery(lqw,true);
        List<GzHolidaysVo> list = iGzHolidaysService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2024-04-24
     * @Param gzHolidays
     * @Return TableDataInfo
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('wage:holidays:add')" )
    @Log(title = "添加广州人事基本工资" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GzHolidaysAdd gzHolidaysAdd) {
        GzHolidays gzHolidays = Convert.convert(new TypeReference<GzHolidays>() {}, gzHolidaysAdd);
        return toAjax(iGzHolidaysService.save(gzHolidays) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2024-04-24
     * @Param gzHolidays
     * @Return TableDataInfo
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('wage:holidays:edit')" )
    @Log(title = "修改广州人事基本工资" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GzHolidaysUpdate gzHolidaysUpdate) {
        GzHolidays gzHolidays = Convert.convert(new TypeReference<GzHolidays>() {}, gzHolidaysUpdate);
        return toAjax(iGzHolidaysService.updateById(gzHolidays) ? 1 : 0);
    }


    /**
     * @Description 导出
     * @Author gpframework
     * @Date 2024-04-24
     * @Param gzHolidays
     * @Return TableDataInfo
     */

    @PreAuthorize("@ss.hasPermi('wage:holidays:export')" )
    @Log(title = "导出广州人事基本工资" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(GzHolidaysReq gzHolidaysReq) {
        QueryWrapper<GzHolidays> lqw = new QueryWrapper<GzHolidays>();
        gzHolidaysReq.generatorQuery(lqw,true);
        List<GzHolidaysVo> list = iGzHolidaysService.listVo(lqw);
        ExcelUtil<GzHolidaysVo> util = new ExcelUtil<GzHolidaysVo>(GzHolidaysVo. class);
        return util.exportExcel(list, "holidays" );
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2024-04-24
     * @Param gzHolidays
     * @Return TableDataInfo
     */
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('wage:holidays:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult<GzHolidaysVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGzHolidaysService.getVoById(id));
    }



    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2024-04-24
     * @Param gzHolidays
     * @Return TableDataInfo
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('wage:holidays:remove')" )
    @Log(title = "删除广州人事基本工资" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iGzHolidaysService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
